import type { Patient, User, UserInfo, codeType } from '@/types/user'
import request from '@/utils/request'

// 手机号码和密码登录
export const loginByPassword = (data: { mobile: string, password: string }) => request<User>('/login/password', 'post', data)

/**
 * 发送短信验证码
 * @param mobile 手机号码
 * @param type 类型
 * @returns
 */
export const sendMobileCode = (mobile: string, type: codeType) => request('/code', 'get', { mobile, type })

// 短信登录
export const loginByMobile = (mobile: string, code: string) => request<User>('/login', 'post', { mobile, code })

// 获取个人用户信息
export const getUserInfo = () => request<UserInfo>('/patient/myUser', 'get')

// 家庭档案-获取患者列表信息
export const getPatientList = () => request<Patient[]>('/patient/mylist')

// 家庭档案-添加患者信息
export const addPatient = (data: Patient) => request('patient/add', 'post', data)

// 家庭档案-编辑患者信息
export const editPatient = (data: Patient) => request('patient/update', 'put', data)

// 家庭档案-患者详情数据
export const patienDetail = (id: string) => request<Patient>(`patient/info/${id}`)

// 家庭档案-删除患者信息
export const delPatient = (id: string) => request(`patient/del/${id}`, 'delete')


// QQ登录
export const loginByQQ = (openId: string, source: string = 'qq') => request<User>('login/thirdparty', 'post', { openId, source })

// 绑定手机号码
export const bindMobile = (data: {
  mobile: string
  code: string
  openId: string
}) => request<User>('login/binding', 'post', data)